﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SCS.DAL;
using SCS.Common.Models;
using System.Linq.Expressions;
namespace SCS.Business
{
    public class ParentServices
    {
        IUnitOfWork _unitOfWork;
        public ParentServices()
        {
            _unitOfWork = new UnitOfWork();
        }

        /// <summary>
        /// getLearnerID
        /// </summary>
        /// <param name="parentID">parentID</param>
        /// <returns>Learner</returns>
        public Learner getLearnerID(int parentID)
        {
            return _unitOfWork.Learner.Get(m => m.parentID == parentID).FirstOrDefault();
        }

        /// <summary>
        /// get Grade
        /// </summary>
        /// <returns>grade list</returns>
        public IList<Grade> Grade()
        {
            return _unitOfWork.Grade.GetAll().OrderByDescending(m => m.createDate).ToList();
        }

        /// <summary>
        /// Grade
        /// </summary>
        /// <param name="learnerID">learnerID</param>
        /// <returns>grade list</returns>
        public IList<Grade> Grade(int learnerID)
        {
            return _unitOfWork.Grade.GetAll().Where(m => m.learnerID == learnerID).OrderByDescending(m => m.createDate).ToList();
        }

        /// <summary>
        /// Grade
        /// </summary>
        /// <param name="learnerID">learnerID</param>
        /// <param name="subjectID">subjectID</param>
        /// <returns>grade list</returns>
        public IList<Grade> Grade(int learnerID, int subjectID)
        {
            return _unitOfWork.Grade.GetAll().Where(m => m.learnerID == learnerID && m.subjectID == subjectID).OrderByDescending(m => m.createDate).ToList();
        }

        /// <summary>
        /// Comment
        /// </summary>
        /// <param name="learnerID">learnerID</param>
        /// <returns>list of comment in class</returns>
        public IList<CommentInClass> Comment(int learnerID)
        {
            return _unitOfWork.Comment.GetAll().Where(m => m.learnerID == learnerID).OrderByDescending(m => m.dateOfComment).ToList();
        }

        /// <summary>
        /// Comment
        /// </summary>
        /// <param name="pageNumber">pageNumber</param>
        /// <param name="pageSize">pageSize</param>
        /// <param name="firstDate">firstDate</param>
        /// <param name="lastDate">lastDate</param>
        /// <param name="learnerID">learnerID</param>
        /// <returns>list of comment in class</returns>
        public IList<CommentInClass> Comment(int pageNumber, int pageSize, DateTime firstDate, DateTime lastDate, int learnerID)
        {
            return _unitOfWork.Comment.SearchGradeInTimePaging(pageNumber, pageSize, firstDate, lastDate, learnerID);
        }

        /// <summary>
        /// GetAllSubject
        /// </summary>
        /// <returns>subject list</returns>
        public IEnumerable<Subject> GetAllSubject()
        {
            return _unitOfWork.Subject.GetAll();
        }

        /// <summary>
        /// TeachingAssignment
        /// </summary>
        /// <returns>teaching assign list</returns>
        public IList<TeachingAssignment> TeachingAssignment()
        {
            return _unitOfWork.TeachingAssignment.GetAll().ToList();
        }

        /// <summary>
        /// GetParent
        /// </summary>
        /// <param name="userID">userID</param>
        /// <returns>parent</returns>
        public Parent GetParent(int userID)
        {
            return _unitOfWork.ParentViewTeacher.Get(m => m.userID == userID).FirstOrDefault();
        }

        /// <summary>
        /// CountParentViewGrade
        /// </summary>
        /// <param name="learnerID">learnerID</param>
        /// <param name="firstDate">firstDate</param>
        /// <param name="lastDate">lastDate</param>
        /// <returns>count</returns>
        public int CountParentViewGrade(int learnerID, DateTime firstDate, DateTime lastDate)
        {
            if (firstDate == null || lastDate == null)
            {
                return _unitOfWork.Parent.GetCount();
            }
            else
            {
                return _unitOfWork.Parent.GetSearchCount(learnerID, firstDate, lastDate);
            }
        }

        /// <summary>
        /// CountParentViewGradeBySubject
        /// </summary>
        /// <param name="learnerID">learnerID</param>
        /// <param name="subjectID">subjectID</param>
        /// <returns>count</returns>
        public int CountParentViewGradeBySubject(int learnerID, int subjectID)
        {
            return _unitOfWork.Parent.GetSearchCount(learnerID, subjectID);
        }

        /// <summary>
        /// CountParentViewComment
        /// </summary>
        /// <param name="firstDate">firstDate</param>
        /// <param name="lastDate">lastDate</param>
        /// <returns>count</returns>
        public int CountParentViewComment(DateTime firstDate, DateTime lastDate)
        {
            if (firstDate == null || lastDate == null)
            {
                return _unitOfWork.Comment.GetCount();
            }
            else
            {
                return _unitOfWork.Comment.GetSearchCount(firstDate, lastDate);
            }
        }

        /// <summary>
        /// CountParentViewTeacherInformation
        /// </summary>
        /// <returns>count</returns>
        public int CountParentViewTeacherInformation()
        {
            return _unitOfWork.Parent.GetCount();
        }

        /// <summary>
        /// Grade
        /// </summary>
        /// <param name="learnerID">learnerID</param>
        /// <param name="pageNumber">pageNumber</param>
        /// <param name="pageSize">pageSize</param>
        /// <param name="firstDate">firstDate</param>
        /// <param name="lastDate">lastDate</param>
        /// <returns>grade list</returns>
        public IList<Grade> Grade(int learnerID, int pageNumber, int pageSize, DateTime firstDate, DateTime lastDate)
        {
            return _unitOfWork.Parent.SearchGradeInTimePaging(learnerID, pageNumber, pageSize, firstDate, lastDate);
        }

        /// <summary>
        /// TeachingAssignment
        /// </summary>
        /// <param name="classID">classID</param>
        /// <param name="schooYearID">schooYearID</param>
        /// <returns>teaching assignment list</returns>
        public IList<TeachingAssignment> TeachingAssignment(int classID, int schooYearID)
        {
            return _unitOfWork.TeachingAssignment.Get(m => m.classID == classID && m.schoolYearID == schooYearID).ToList();
        }

        /// <summary>
        /// getLastSchoolYear
        /// </summary>
        /// <returns>last school year</returns>
        public string getLastSchoolYear()
        {
            return _unitOfWork.SchoolYear.GetAll().LastOrDefault().schoolYearName;
        }

        /// <summary>
        /// getClassName
        /// </summary>
        /// <param name="classID">classID</param>
        /// <returns>class name</returns>
        public string getClassName(int classID)
        {
            return _unitOfWork.ClassInSchoolYear.GetAll().Where(c => c.classID == classID).FirstOrDefault().className;
        }
    }
}